<?php

class JSONHelper {
    /**
     *  retInfo:根据状态json化返回值
     *  @param status 执行的状态
     * 			info 返回的信息
     *  @return json字符串;
     */
    

        const MAN = 1;
    const WOMAN = 2;
    
    const ERROR = 1;
    const SUCCESS =0;//请求成功
    //下面都是错误码
    const TYPE_JSON = 10;
    const ERROR_ILLEGAL_REQUEST = 400; //非法请求，请求参数个数或者类型错误
    const ILLEGAL_TELEPHONE = 401; //手机号码非法
    const REPEAT_TELEPHONE = 402; //手机号码重复
    const ILLEGAL_EMAIL = 403; //邮箱非法
    const REPEAT_EMAIL = 404; //EMAIL重复
    const ILLEGAL_PASSWORD = 405; //密码格式错误
    const ILLEGAL_IDENTITY_NO = 406; //身份证号码不合法
    const ILLEGAL_LOGIN = 407; //登录用户名或者密码不正确
    
    const ERROR_ILLEGAL_UID = 408; //没有获取到uid
    const ERROR_USER_EXISTS = 409; //用户已经存在
    const ERROR_SERVICE = 414; //数据库异常
    const ERROR_ILLEGAL_ACTIVECODE = 445;//激活码错误
    const ERROR_ACTIVECODE_USED = 446;//激活码错误
   



    const ERROR_SMS_SERVICE = 460;//短信服务器异常
    const ERROR_SMS_FRUQUENCY = 461;//短信服务请求频繁
    const ERROR_SMS_VERIFY = 462;//校验失败
    
    const ERROR_NOEXIST_USER = 480;//用户不存在
    
    static function retInfo($status, $info = null, $type = self::TYPE_JSON) {
        if ($type == self::TYPE_JSON) {
            header('Content-Type: application/json');
        }
        $ret = array();
//        if ($status) {
//            $ret['status'] = JSONHelper::SUCCESS;
//        } else {
//            $ret['status'] = JSONHelper::ERROR;
//        }
        $ret['status']=$status; 
        $ret['data'] = $info;
        return json_encode($ret);
    }
    
    static function echoJSON($status, $info = null, $type = self::TYPE_JSON) {
        echo self::retInfo($status, $info, $type);
        exit();
    }
//    static function echoErrorCode($status, $info = null, $type = self::TYPE_JSON) {
//        echo self::retInfo($status, $info, $type);
//        exit();
//    }

}